package cn.itcast.bos.service;

import javax.jms.JMSException;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.itcast.bos.dao.WayBillDao;
import cn.itcast.bos.domain.take_delivery.WayBill;
import cn.itcast.bos.index.WayBillIndexDao;

@Service
public class SaveIndex implements MessageListener {
	// 注入运单的数据库
	@Autowired
	private WayBillDao wbd;
	// 注入索引数据库
	@Autowired
	private WayBillIndexDao wayBillIndexDao;

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage) message;
		try {
			Integer id = mapMessage.getInt("id");
			WayBill wayBill = wbd.findOne(id);
			// 自动创建索引
			wayBillIndexDao.save(wayBill);
			// 通过数据库查询数对象
		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
